<?php
/**
 * Created by PhpStorm.
 * User: zhu
 * Date: 2016/10/19
 * Time: 21:44
 */

namespace Lavender;

abstract class ASignature {
    /**
     * 加密key
     * @var string
     */
    protected $_key = '';
    /**
     * 加密方式
     * @var string
     */
    protected $_sign_type = 'md5';
    /**
     * charset
     * @var string
     */
    protected $_input_charset = 'utf-8';

    /**
     * 需要过滤掉的参数数组
     * eg. array('sign' => 1, 'sign_type' => 1)
     * @var array
     */
    protected $_filter_params = array();

    /**
     * 构造方法
     * @param string $key 密钥
     * @param string $sign_type 加密方式
     * @param array  $filters  要过滤的参数数组
     * @param string $charset  字符编码
     */
    public function __construct($key = '', $sign_type = '', $filters = array(), $charset = '')
    {
        if (!empty($key)) {
            $this->_key = $key;
        }
        if (!empty($sign_type)) {
            $this->_sign_type = $sign_type;
        }
        if (!empty($filters) && is_array($filters)) {
            $this->_filter_params = $filters;
        }
        if (!empty($charset)) {
            $this->_input_charset = $charset;
        }
    }

    /**
     * @param array $params
     * @return string
     */
    abstract public function get_signature($params);

    /**
     * @param $encryption_string
     * @return string
     */
    abstract public function sign($encryption_string);
}